package com.tekj.cxqcb.view.Module.activity;

import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.tekj.cxqcb.R;
import com.tekj.cxqcb.operation.BusinessDao;
import com.tekj.cxqcb.operation.resultBean.SelectDetailBean;
import com.tekj.cxqcb.operation.resultBean.SelectExpandDetailBean;

import butterknife.BindView;
import butterknife.OnClick;
import common.base.activity.BaseActivity;
import common.base.operationHelper.Bean.BindingViewBean;
import common.tool.Tools;
import common.widget.CircleTransform;

/**
 * 下级详情
 */
public class SubordinateDetailsActivity extends BaseActivity {
    @BindView(R.id.img_back)
    ImageView imgBack;
    @BindView(R.id.tv_l)
    TextView tvL;
    @BindView(R.id.ll_back)
    LinearLayout llBack;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.iv_r)
    ImageView ivR;
    @BindView(R.id.tv_r)
    TextView tvR;
    @BindView(R.id.ll_right)
    LinearLayout llRight;
    @BindView(R.id.rl_title_bg)
    RelativeLayout rlTitleBg;
    @BindView(R.id.img_head)
    ImageView imgHead;
    @BindView(R.id.item_tv_name)
    TextView itemTvName;
    @BindView(R.id.item_tv_identity)
    TextView itemTvIdentity;
    @BindView(R.id.tv_phone)
    TextView tvPhone;
    @BindView(R.id.item_tv_region)
    TextView itemTvRegion;
    @BindView(R.id.item_tv_time)
    TextView itemTvTime;
    @BindView(R.id.tv_buy_car_num)
    TextView tvBuyCarNum;
    @BindView(R.id.ll_superior)
    LinearLayout llSuperior;
    @BindView(R.id.tv_all_num)
    TextView tvAllNum;
    @BindView(R.id.tv_conduct)
    TextView tvConduct;
    @BindView(R.id.tv_complete_num)
    TextView tvCompleteNum;
    @BindView(R.id.tv_close_num)
    TextView tvCloseNum;
    @BindView(R.id.tv_selling_money)
    TextView tvSellingMoney;
    @BindView(R.id.tv_recommend_money)
    TextView tvRecommendMoney;
    @BindView(R.id.tv_subsidy_money)
    TextView tvSubsidyMoney;
    @BindView(R.id.tv_all_money)
    TextView tvAllMoney;

    BusinessDao businessDao;
    SelectExpandDetailBean.DataBean.ListBean listBean;

    @Override
    public void init() {
        listBean = (SelectExpandDetailBean.DataBean.ListBean) getIntent().getSerializableExtra("id");
        businessDao = new BusinessDao(this, this);
        businessDao.SelectDetail(listBean.getId());
        tvTitle.setText("详情");
    }

    @Override
    public int setLayout() {
        return R.layout.activity_subordinate_details;
    }

    boolean isFirst;

    @Override
    public void initLoadStart() {
        if (isFirst) {
            loading.show();
            isFirst = false;
        }
    }

    @Override
    public void initLoadEnd() {
        loading.dismiss();
    }

    @Override
    public void initBindingView(Object mBean) {
        BindingViewBean bindingViewBean = (BindingViewBean) mBean;
        switch (bindingViewBean.getmEnumStatus()) {
            case 查看我的关联渠道详情:
                SelectDetailBean selectDetailBean = (SelectDetailBean) bindingViewBean.getBean();
                if (selectDetailBean.getCode().equals("0000000")) {
                    setViewData(selectDetailBean.getData());
                }
                break;
        }
    }


    @OnClick(R.id.ll_back)
    public void onViewClicked() {
        finish();
    }

    void setViewData(SelectDetailBean.DataBean bean) {

        Picasso.get()
                .load(listBean.getHead())
                .transform(new CircleTransform())
                .error(R.mipmap.icon_head)
                .placeholder(R.mipmap.icon_head)
                .into(imgHead);

        itemTvName.setText(listBean.getName() + "");
//        itemTvIdentity.setText(bean.get);

        itemTvRegion.setText(listBean.getAddress() + "");
        itemTvTime.setText(listBean.getCreateTime() + "");
        tvAllNum.setText(bean.getOrderAll() + "");

        tvCompleteNum.setText(bean.getCompleted() + "");
        tvConduct.setText(bean.getOrdering() + "");
        tvCloseNum.setText(bean.getClosed() + "");
        tvSellingMoney.setText(bean.getSellCarAward() + "");

        String numString = "累计完成售车订单" + listBean.getSalesCarAll() + "单";
        tvBuyCarNum.setText(
                Tools.setTextColor(activity, numString, R.color.colorPrimary,
                        numString.indexOf("单") + 1, numString.length() - 1));
        tvRecommendMoney.setText(bean.getRecommendAward() + "");
        tvSubsidyMoney.setText(bean.getSubsidy() + "");

        String identity = "";
        if (listBean.getRole().equals("4")) {
            identity = "城市合伙人";
            RelatedChannelsActivity.setTextColorBG(activity, itemTvIdentity, 2);
        } else if (listBean.getRole().equals("5") || listBean.getRole().equals("6")) {
            identity = "运管中心";
            RelatedChannelsActivity.setTextColorBG(activity, itemTvIdentity, 1);
        } else if (listBean.getRole().equals("7") || listBean.getRole().equals("8")) {
            identity = "省分公司";
            RelatedChannelsActivity.setTextColorBG(activity, itemTvIdentity, 3);
        }
        itemTvIdentity.setText(identity);
        tvAllMoney.setText(bean.getTotal() + "");
    }

}
